var dbUtil = require('./dbUtil')


/***
 *  1. 查询所有
 *  2. 按productId查询库存——为出入库做准备
 *  3. 修改库存
 * */

function selectAll(callback) {

    var sql = "select  * from stock_balance ";
    dbUtil.query(sql,null,function (err,rows) {
        callback(rows)
    })

}

function selectByProductId(productId,callback) {
    var sql = "select  * from stock_balance where product_id = ?";
    var params = [productId]

    dbUtil.query(sql,params,function (error,rows,fields) {
        callback(rows);
    })
}

function update(balanceObj,callback){

    var sql = "update stock_balance\n" +
        "set quantity= ?\n" +
        "where stock_id = ?";
    var params=[balanceObj.quantity,balanceObj.stock_id];

    dbUtil.query(sql,params,function (error,result) {
        callback(result)
    })
}


module.exports = {
    selectAll,
    selectByProductId,
    update
}